﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using Microsoft.Data.Odbc;

namespace Mediatheque
{
    public partial class Form1 : Form
    {
        private System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        private const int WM_NCLBUTTONDBLCLK = 0x0A3;
        private const int WM_NCHITTEST = 0x0084;
        private const int HTCLIENT = 1;
        private const int HTCAPTION = 2;
        private Connexion connexion = new Connexion();
        private Utile outil = new Utile();
        private UserControl ct = new UserControl();
        private string reference = "";

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_NCLBUTTONDBLCLK)
            {
                m.Result = IntPtr.Zero;
                return;
            }

            base.WndProc(ref m);

            if (m.Msg == WM_NCHITTEST)
            {
                if (m.Result == (IntPtr)HTCLIENT)
                {
                    m.Result = (IntPtr)HTCAPTION;
                    return;
                }
            }
        }
        public Form1()
        {   
            InitializeComponent();       
        }
        

        private void pictureBox2_MouseLeave(object sender, EventArgs e)
        {
            this.fermerFinal.Visible = false;
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            this.fermerFinal.Visible = true;
        }

        private void pictureBox3_MouseEnter(object sender, EventArgs e)
        {
            this.reduireFinal.Visible = true;
        }

        private void pictureBox4_MouseLeave(object sender, EventArgs e)
        {
            this.reduireFinal.Visible = false;
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void ListeDesAdherentsTrans_MouseEnter(object sender, EventArgs e)
        {
            this.ListeDesAdherentsValid.Visible = true;
        }

        private void ListeDesAdherentsValid_MouseLeave(object sender, EventArgs e)
        {
            this.ListeDesAdherentsValid.Visible = false;
        }

        private void AjouterUnAdherentTrans_MouseEnter(object sender, EventArgs e)
        {
            this.AjouterUnAdherentValid.Visible = true;
        }

        private void AjouterUnAdherentValid_MouseLeave(object sender, EventArgs e)
        {
            this.AjouterUnAdherentValid.Visible = false;
        }

        private void SupprimerUnAdherentTrans_MouseEnter(object sender, EventArgs e)
        {
            this.SupprimerUnAdherentValid.Visible = true;
        }

        private void SupprimerUnAdherentValid_MouseLeave(object sender, EventArgs e)
        {
            this.SupprimerUnAdherentValid.Visible = false;
        }

        private void ModifierUnAdherentTrans_MouseEnter(object sender, EventArgs e)
        {
            this.ModifierUnAdherentValid.Visible = true;
        }

        private void ModifierUnAdherentValid_MouseLeave(object sender, EventArgs e)
        {
            this.ModifierUnAdherentValid.Visible = false;
        }

        private void LisetDesMediasTrans_MouseEnter(object sender, EventArgs e)
        {
            this.ListDesMediasValid.Visible = true;
        }

        private void ListDesMediasValid_MouseLeave(object sender, EventArgs e)
        {
            this.ListDesMediasValid.Visible = false;
        }

        private void AjouterUnMediaTrans_MouseEnter(object sender, EventArgs e)
        {
            this.AjouterUnMediaValid.Visible = true;
        }

        private void AjouterUnMediaValid_MouseLeave(object sender, EventArgs e)
        {
            this.AjouterUnMediaValid.Visible = false;
        }

        private void SupprimerUnMediaTrans_MouseEnter(object sender, EventArgs e)
        {
            this.SupprimerUnMediaValid.Visible = true;
        }

        private void SupprimerUnMediaValid_MouseLeave(object sender, EventArgs e)
        {
            this.SupprimerUnMediaValid.Visible = false;
        }

        private void ModifierUnMediaTrans_MouseEnter(object sender, EventArgs e)
        {
            this.ModifierUnMediaValid.Visible = true;
        }

        private void ModifierUnMediaValid_MouseLeave(object sender, EventArgs e)
        {
            this.ModifierUnMediaValid.Visible = false;
        }

        private void ListeDesEmpruntsTrans_MouseEnter(object sender, EventArgs e)
        {
            this.ListDesEmpruntsValid.Visible = true;
        }

        private void ListDesEmpruntsValid_MouseLeave(object sender, EventArgs e)
        {
            this.ListDesEmpruntsValid.Visible = false;
        }

        
        private void EmprunterUnMediaTrans_MouseEnter(object sender, EventArgs e)
        {
            this.EmprunterUnMediaValid.Visible = true;
        }

        private void EmprunterUnMediaValid_MouseLeave(object sender, EventArgs e)
        {
            this.EmprunterUnMediaValid.Visible = false;
        }

        private void CleanAjouterAdherent()
        {
            this.Nom_adherent.Visible = false;
            this.Prenom_adherent.Visible = false;
            this.Email_adherent.Visible = false;
            this.Adresse_Adherent.Visible = false;
            this.BoutonMlle.Visible = false;
            this.BoutonMme.Visible = false;
            this.BoutonMr.Visible = false;
            this.BoutonAjouterUnAdherent.Visible = false;
            this.AjouterUnAdherentInterface.Visible = false;
        }
        private void AjouterUnAdherentValid_Click(object sender, EventArgs e)
        {
           
            this.Nom_adherent.Visible = true;
            this.Prenom_adherent.Visible = true;
            this.Email_adherent.Visible = true;
            this.Adresse_Adherent.Visible = true;
            this.Nom_adherent.Text = "";
            this.Prenom_adherent.Text = "";
            this.Email_adherent.Text = "";
            this.Adresse_Adherent.Text = "";
            this.BoutonMlle.Visible = true;
            this.BoutonMme.Visible = true;
            this.BoutonMr.Visible = false;
            this.BoutonAjouterUnAdherent.Visible = true;
            this.AjouterUnAdherentInterface.Visible = true;

            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanListMedia();
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();
            
           
            PictureClean();
        }

        private void Back_MouseEnter(object sender, EventArgs e)
        {
            this.BackFinal.Visible = true;
        }

        private void BackFinal_MouseLeave(object sender, EventArgs e)
        {
            this.BackFinal.Visible = false;
        }

        private void BackFinal_Click(object sender, EventArgs e)
        {
            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanListMedia();
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();


            PictureClean();
        }

        private void Power_MouseEnter(object sender, EventArgs e)
        {
            this.PowerFinal.Visible = true;
        }

        private void PowerFinal_MouseLeave(object sender, EventArgs e)
        {
            this.PowerFinal.Visible = false;
        }

        private void PowerFinal_Click(object sender, EventArgs e)
        {
            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanListMedia();
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();


            PictureClean();
           
        }

        private void BoutonMlle_Click(object sender, EventArgs e)
        {
            this.BoutonMlle.Visible = false;
            this.BoutonMr.Visible = true;
            this.BoutonMme.Visible = true;
        }

        private void BoutonMr_Click(object sender, EventArgs e)
        {
            this.BoutonMr.Visible = false;
            this.BoutonMme.Visible = true;
            this.BoutonMlle.Visible = true;
        }

        private void BoutonMme_Click(object sender, EventArgs e)
        {
            this.BoutonMme.Visible = false;
            this.BoutonMlle.Visible = true;
            this.BoutonMr.Visible = true;
        }

        private void BoutonAjouterUnAdherent_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUnAdherent.Visible = false;
            this.BoutonAjouterUnAdherentHover.Visible = true;
        }

       

        private void BoutonAjouterUnAdherentHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUnAdherentHover.Visible = false;
            this.BoutonAjouterUnAdherent.Visible = true;
        }

        private void CleanSupprmierAdherent()
        {
            this.Nom_AdherentSuppr.Visible = false;
            this.Prenom_AdherentSuppr.Visible = false;
            this.ListAdhérentsSuppr.Visible = false;
            this.BoutonSupprimerSupprAdhe.Visible = false;
            this.BoutonSupprimerSupprAdheHover.Visible = false;
            this.SupprimerUnAdherentInterface.Visible = false;
        }

        private void SupprimerUnAdherentValid_Click(object sender, EventArgs e)
        {

            this.BoutonSupprimerSupprAdheHover.BringToFront();
            this.BoutonSupprimerSupprAdhe.BringToFront();
            

            this.Nom_AdherentSuppr.Visible = true;
            this.Prenom_AdherentSuppr.Visible = true;
            this.Nom_AdherentSuppr.Text = "";
            this.Prenom_AdherentSuppr.Text = "";
            this.ListAdhérentsSuppr.Visible = true;
            this.BoutonSupprimerSupprAdhe.Visible = true;
            this.BoutonSupprimerSupprAdheHover.Visible = true;
            this.SupprimerUnAdherentInterface.Visible = true;

            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanListMedia();

            this.BoutonModifierAdherent.Visible = false;
            this.BoutonModifierAdherenthover.Visible = false;
            //CleanModifierAdherent();

            CleanModifierMedia();
            CleanSupprimerMedia();
            
            PictureClean();
           
            
            
        }

        private void BoutonSupprimerSupprAdhe_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonSupprimerSupprAdhe.Visible = false;
            this.BoutonSupprimerSupprAdheHover.Visible = true;
        }

        private void BoutonSupprimerSupprAdheHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonSupprimerSupprAdhe.Visible = true;
            this.BoutonSupprimerSupprAdheHover.Visible = false;
        }

        private void BoutonAjouterUnAdherentHover_Click(object sender, EventArgs e)
        {
            
            
            if (this.Nom_adherent.Text != ""
                && this.Prenom_adherent.Text != ""
                && this.Email_adherent.Text != ""
                && this.Adresse_Adherent.Text != "")
            {
                List<string> values = new List<string>();
                Adherent adherent = new Adherent();
               

                values.Add("'" + outil.echappement(this.Prenom_adherent.Text) + "'");
                values.Add("'" + outil.echappement(this.Nom_adherent.Text) + "'");
                if(this.BoutonMme.Visible == false
                   && this.BoutonMlle.Visible == true
                   && this.BoutonMr.Visible == true)
                    values.Add("'" +"Mme" + "'");
                if (this.BoutonMme.Visible == true
                  && this.BoutonMlle.Visible == false
                  && this.BoutonMr.Visible == true)
                    values.Add("'" + "Mlle" + "'");
                if (this.BoutonMme.Visible == true
                  && this.BoutonMlle.Visible == true
                  && this.BoutonMr.Visible == false)
                    values.Add("'" + "M" + "'");
                values.Add("'" + outil.echappement(this.Email_adherent.Text) + "'");
                values.Add("'" + outil.echappement(this.Adresse_Adherent.Text)+"'");

                connexion.Insert("adherent", adherent.Champs, values, false);

                MessageBox.Show("L'adhérent a bien été ajouté");
                AjouterUnAdherentValid_Click(sender, e);

                
            }
            else
                MessageBox.Show("Veuillez remplir les champs");

        }


        private void BoutonRechercherSupprAdheHover_Click_1(object sender, EventArgs e)
        {
            RechercheAdherentSuppr();  
        }

        private void BoutonSupprimerSupprAdheHover_Click(object sender, EventArgs e)
        {
            if (this.Nom_AdherentSuppr.Text != ""
                || this.Prenom_AdherentSuppr.Text != ""
               )
            {
                for (int i = 0; i < ListAdhérentsSuppr.CheckedItems.Count; i++)
                {
                    connexion.DeleteByID("adherent", "identifiant", outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[i], ' ')[1]);
                    ListAdhérentsSuppr.Items.Remove(ListAdhérentsSuppr.CheckedItems[i]);
                }
                MessageBox.Show("Adhérent supprimé");
                SupprimerUnAdherentValid_Click(sender, e);
            }

            else
                MessageBox.Show("Veuillez remplir les champs");
            
              
            
        }
        private void RechercheAdherentSuppr()
        {
            ListAdhérentsSuppr.Items.Clear();
            List<string> values = new List<string>();
            List<string> champs = new List<string>();

            if (this.Prenom_AdherentSuppr.Text != "")
            {
                values.Add(Prenom_AdherentSuppr.Text);
                champs.Add("prenom");
            }
            if (this.Nom_AdherentSuppr.Text != "")
            {
                values.Add(Nom_AdherentSuppr.Text);
                champs.Add("nom");
            }
            List<string> tmp = connexion.rechercheGlobale("adherent", champs, values, 0, 3);
            foreach (string t in tmp)
                ListAdhérentsSuppr.Items.Add("Rèf. " + t);
        }

        private void CleanListAdherent()
        {
            this.ListedesAdherents.Visible = false;
            this.ListeDesAdherentsInterface.Visible = false;
        }
        private void ListeDesAdherentsValid_Click(object sender, EventArgs e)
        {
            this.ListedesAdherents.Visible = true;
            this.ListeDesAdherentsInterface.Visible = true;

            ListedesAdherents.Items.Clear();

            CleanAjouterAdherent();
            CleanAjouterMedia();
            this.ListEmpruntAdherent.Visible = false;
            this.ListEmpruntContenu.Visible = false;
            this.ValiderEmprunt.Visible = false;
            this.ListeDesEmprunts.Visible = false;
            this.BoutonValiderEmprunt.Visible = false;
            this.ListeDesMedias.Visible = false;
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();
            PictureClean();

            List<string> tmp = connexion.SelectionGlobale("adherent","nom", 0, 4);
            foreach (string t in tmp)
                ListedesAdherents.Items.Add("Rèf. " + t);      
        }


        private void CleanModifierAdherent()
        {
            this.BoutonModifierAdherent.Visible = false;
            this.BoutonModifierAdherenthover.Visible = false;
            this.ListAdhérentsSuppr.Visible = false;
            this.Nom_AdherentSuppr.Visible = false;
            this.Prenom_AdherentSuppr.Visible = false;
            this.SupprimerUnAdherentInterface.Visible = false;
        }
        private void ModifierUnAdherentValid_Click(object sender, EventArgs e)
        {
            this.BoutonModifierAdherenthover.BringToFront();
            this.BoutonModifierAdherent.BringToFront();
            
            this.BoutonModifierAdherent.Visible = true;
            this.BoutonModifierAdherenthover.Visible = true;
            this.ListAdhérentsSuppr.Visible = true;
            this.ListAdhérentsSuppr.Items.Clear();
            this.Nom_AdherentSuppr.Visible = true;
            this.Prenom_AdherentSuppr.Visible = true;
            this.Nom_AdherentSuppr.Text = "";
            this.Prenom_AdherentSuppr.Text = "";
            this.SupprimerUnAdherentInterface.Visible = true;

            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanListMedia();
            CleanModifierMedia();
            CleanSupprimerMedia();
            
            
            PictureClean();   
        }

        private void BoutonModifierAdherent_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonModifierAdherent.Visible = false;
            this.BoutonModifierAdherenthover.Visible = true;
        }

        private void BoutonModifierAdherenthover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonModifierAdherenthover.Visible = false;
            this.BoutonModifierAdherent.Visible = true;
        }

        private void Nom_AdherentSuppr_KeyUp(object sender, KeyEventArgs e)
        {
            RechercheAdherentSuppr();
        }

        private void Prenom_AdherentSuppr_KeyUp(object sender, KeyEventArgs e)
        {
            RechercheAdherentSuppr();
        }

        private void BoutonModifierAdherenthover_Click(object sender, EventArgs e)
        {
            if (this.Nom_AdherentSuppr.Text == ""
               && this.Prenom_AdherentSuppr.Text == ""
              )
                MessageBox.Show("Veuillez remplis les champs");
            else if (ListAdhérentsSuppr.CheckedItems.Count == 1)
            {

                this.BoutonValiderAdherentModif.BringToFront();
                this.BoutonValiderAdherentModifHover.BringToFront();
                this.BoutonValiderAdherentModifHover.Visible = true;
                this.BoutonValiderAdherentModif.Visible = true;
                this.AjouterUnAdherentInterface.Visible = true;

                this.Nom_adherent.Visible = true;
                this.Prenom_adherent.Visible = true;
                this.Email_adherent.Visible = true;
                this.Adresse_Adherent.Visible = true;

               

                this.Nom_adherent.Text = outil.mySplit( connexion.SearchById("adherent", "identifiant", outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]),' ')[2];
                this.Prenom_adherent.Text = outil.mySplit(connexion.SearchById("adherent", "identifiant", outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]), ' ')[1];
                this.Email_adherent.Text = outil.mySplit(connexion.SearchById("adherent", "identifiant", outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]), ' ')[4];
                this.Adresse_Adherent.Text = outil.mySplit(connexion.SearchById("adherent", "identifiant", outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]), ' ')[5];

               

                this.BoutonMlle.Visible = true;
                this.BoutonMme.Visible = true;
                this.BoutonMr.Visible = false;
                this.BoutonAjouterUnAdherent.Visible = false;

                this.SupprimerUnAdherentInterface.Visible = false;
                this.BoutonSupprimerSupprAdhe.Visible = false;
                this.BoutonSupprimerSupprAdheHover.Visible = false;
                this.Nom_AdherentSuppr.Visible = false;
                this.Prenom_AdherentSuppr.Visible = false;
                this.ListAdhérentsSuppr.Visible = false;

                this.ListeDesAdherentsInterface.Visible = false;
                this.ListedesAdherents.Visible = false;
            }
            else if (ListAdhérentsSuppr.CheckedItems.Count > 1)
                MessageBox.Show("Vous avez selectionnés trop d'items");
            else
                MessageBox.Show("Veillez selectionner un item");

            

           

            
        }

        private void BoutonValiderAdherentModif_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonValiderAdherentModif.Visible = false;
            this.BoutonValiderAdherentModifHover.Visible = true;
        }

        private void BoutonValiderAdherentModifHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonValiderAdherentModifHover.Visible = false;
            this.BoutonValiderAdherentModif.Visible = true;
        }

        private void BoutonValiderAdherentModifHover_Click(object sender, EventArgs e)
        {
            connexion.Update("adherent", "prenom", this.Nom_adherent.Text, " identifiant =" + outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]);
            connexion.Update("adherent", "nom", this.Prenom_adherent.Text, " identifiant =" + outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]);
            connexion.Update("adherent", "mail", this.Email_adherent.Text, " identifiant =" + outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]);
            connexion.Update("adherent", "adresse", this.Adresse_Adherent.Text, " identifiant =" + outil.mySplit((string)ListAdhérentsSuppr.CheckedItems[0], ' ')[1]);

            MessageBox.Show("Adhérent modifié");

            ModifierUnAdherentValid_Click(sender, e);

        }

        private void CleanListMedia()
        {
            this.ListeDesMedias.Visible = false;
            this.ListeDesAdherentsInterface.Visible = false;
        }
        private void ListDesMediasValid_Click(object sender, EventArgs e)
        {
            
            this.ListeDesMedias.BringToFront();
            this.ListeDesMedias.Visible = true;
            this.ListeDesAdherentsInterface.Visible = true;
            

            // Set the column header names.
            this.ListeDesMedias.Rows.Clear();
            this.ListeDesMedias.ColumnCount = 4;
            this.ListeDesMedias.ColumnHeadersVisible = true;

            this.ListeDesMedias.Columns[0].Name = "Réf";
            this.ListeDesMedias.Columns[1].Name = "Type";
            this.ListeDesMedias.Columns[2].Name = "Support";
            this.ListeDesMedias.Columns[3].Name = "Description";
            this.ListeDesMedias.Columns[0].Width = 30;
            this.ListeDesMedias.Columns[2].Width = 60;
            this.ListeDesMedias.Columns[3].Width = 1000;

            this.ListeDesMedias.DefaultCellStyle.ForeColor= Color.White;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
            dataGridViewCellStyle2.BackColor = System.Drawing.Color.LightSlateGray;
           
            this.ListeDesMedias.ColumnHeadersDefaultCellStyle =dataGridViewCellStyle2;
            this.ListeDesMedias.EnableHeadersVisualStyles = false;
            this.ListeDesMedias.RowsDefaultCellStyle.BackColor = Color.CornflowerBlue;
            this.ListeDesMedias.AlternatingRowsDefaultCellStyle.BackColor = Color.SteelBlue;

            List<string[]> tmp_list = connexion.rechercheGlobaleList("contenu", "titre", 4);

            foreach (string[] tmp in tmp_list)
            {
            
                this.ListeDesMedias.Rows.Add(tmp);
            }


            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            //CleanListAdherent();
            this.ListedesAdherents.Visible = false;
            //CleanListEmprunt();
            this.ListeDesEmprunts.Visible = false;
            this.BoutonValiderEmprunt.Visible = false;
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();
            PictureClean();
            
           


        }

        private void CleanAjouterMedia()
        {
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.BoutonCarte.Visible = false;
            this.BoutonJournal.Visible = false;
            this.BoutonLivre.Visible = false;
            this.BoutonMusique.Visible = false;
            this.BoutonPartition.Visible = false;
            this.BoutonVideo.Visible = false;
            this.TitreMedia.Visible = false;
            this.DescriptionMedia.Visible = false;
            this.AjouterUnMediaInterface.Visible = false;
        
        }

        private void AjouterUnMediaValid_Click(object sender, EventArgs e)
        {
            BoutonAjouterMediaEnable();
            this.BoutonCarte.BringToFront();
            this.PaysCarte.Visible = true;
            this.PaysCarteMedia.Visible = true;
            this.RegionCarte.Visible = true;
            this.RegionCarteMedia.Visible = true;
            this.BoutonAjouterUneCarte.Visible = true;
            this.PaysCarte.Text = "";
            this.RegionCarte.Text = "";

            this.BoutonCarte.Visible = false;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = true;
            this.TitreMedia.Visible = true;
            this.TitreMedia.Text = "";
            this.DescriptionMedia.Visible = true;
            this.DescriptionMedia.Text = "";
            this.AjouterUnMediaInterface.Visible = true;


            CleanAjouterAdherent();
            
            CleanEmprunterMedia();
            CleanListMedia();
            CleanListAdherent();          
            CleanListEmprunt();
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();
            

        }

        private void BoutonCarte_Click(object sender, EventArgs e)
        {
            this.PaysCarte.Visible = true;
            this.PaysCarteMedia.Visible = true;
            this.RegionCarte.Visible = true;
            this.RegionCarteMedia.Visible = true;
            this.BoutonAjouterUneCarte.Visible = true;
            this.PaysCarte.Text = "";
            this.RegionCarte.Text = "";

            this.BoutonCarte.Visible = false;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = true;
            this.PaysCarte.Visible = true;
            this.PaysCarteMedia.Visible = true;
            this.RegionCarte.Visible = true;
            this.RegionCarteMedia.Visible = true;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;

        }

        
        private void BoutonJournal_Click(object sender, EventArgs e)
        {

            this.DateJournal.Visible = true;
            this.DateJournalMedia.Visible = true;
            this.NomJournal.Visible = true;
            this.NomJournalMedia.Visible = true;
            this.BoutonAjouterUnJournal.Visible = true;
            this.DateJournal.Text = "";
            this.NomJournal.Text = "";
        
            this.BoutonCarte.BringToFront();
            this.BoutonCarte.Visible = true;
            this.BoutonJournal.Visible = false;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = true;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;

        }

        private void BoutonLivre_Click(object sender, EventArgs e)
        {

            this.AuteurLivre.Visible = true;
            this.AuteurLivreMedia.Visible = true;
            this.EditeurLivre.Visible = true;
            this.EditeurLivreMedia.Visible = true;
            this.BoutonAjouterUnLivre.Visible = true;
            this.AuteurLivre.Text = "";
            this.EditeurLivre.Text = "";

            this.BoutonCarte.BringToFront();
            this.BoutonCarte.Visible = true;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = false;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = true;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;
        }

        private void BoutonMusique_Click(object sender, EventArgs e)
        {
            this.GenreMusique.Visible = true;
            this.GenreMusiqueMedia.Visible = true;
            this.CompositeurMusique.Visible = true;
            this.CompositeurMusiqueMedia.Visible = true;
            this.BoutonAjouterUneMusique.Visible = true;
            this.GenreMusique.Text = "";
            this.CompositeurMusique.Text = "";

            this.BoutonCarte.BringToFront();
            this.BoutonCarte.Visible = true;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = false;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = true;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;
        }

        private void BoutonPartition_Click(object sender, EventArgs e)
        {
            this.GenrePartition.Visible = true;
            this.GenrePartitionMedia.Visible = true;
            this.BoutonAjouterUnePartition.Visible = true;
            this.GenrePartition.Text = "";
            
            this.BoutonCarte.BringToFront();
            this.BoutonCarte.Visible = true;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = false;
            this.BoutonVideo.Visible = true;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;
        }

        private void BoutonVideo_Click(object sender, EventArgs e)
        {
            this.RealisateurVideo.Visible = true;
            this.RealisateurVideoMedia.Visible = true;
            this.ProducteurVideo.Visible = true;
            this.ProducteurVideoMedia.Visible = true;
            this.BoutonAjouterUneVideo.Visible = true;
            this.RealisateurVideo.Text = "";
            this.ProducteurVideo.Text = "";
            
            this.BoutonCarte.BringToFront();
            this.BoutonCarte.Visible = true;
            this.BoutonJournal.Visible = true;
            this.BoutonLivre.Visible = true;
            this.BoutonMusique.Visible = true;
            this.BoutonPartition.Visible = true;
            this.BoutonVideo.Visible = false;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
        }

        private void BoutonAjouterUneCarte_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUneCarte.Visible = false;
            this.BoutonAjouterUneCarteHover.Visible = true;
        }

        private void BoutonAjouterUneCarteHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUneCarteHover.Visible = false;
            this.BoutonAjouterUneCarte.Visible = true;
            
        }

        private void BoutonAjouterUnJournal_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUnJournal.Visible = false;
            this.BoutonAjouterUnJournalHover.Visible = true;
        }

        private void BoutonAjouterUnJournalHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUnJournalHover.Visible = false;
            this.BoutonAjouterUnJournal.Visible = true;
        }

        private void BoutonAjouterUnLivre_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUnLivre.Visible = false;
            this.BoutonAjouterUnLivreHover.Visible = true;
        }

        private void BoutonAjouterUnLivreHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUnLivreHover.Visible = false;
            this.BoutonAjouterUnLivre.Visible = true;
        }

        private void BoutonAjouterUneMusique_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUneMusique.Visible = false;
            this.BoutonAjouterUneMusiqueHover.Visible = true;
        }

        private void BoutonAjouterUneMusiqueHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUneMusiqueHover.Visible = false;
            this.BoutonAjouterUneMusique.Visible = true;
        }

        private void BoutonAjouterUnePartition_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUnePartition.Visible = false;
            this.BoutonAjouterUnePartitionHover.Visible = true;
        }

        private void BoutonAjouterUnePartitionHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUnePartitionHover.Visible = false;
            this.BoutonAjouterUnePartition.Visible = true;
        }

        private void BoutonAjouterUneVideo_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonAjouterUneVideo.Visible = false;
            this.BoutonAjouterUneVideoHover.Visible = true;
        }

        private void BoutonAjouterUneVideoHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonAjouterUneVideoHover.Visible = false;
            this.BoutonAjouterUneVideo.Visible = true;
        }

        private void BoutonAjouterUneCarteHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Carte carte = new Carte();
            carte.Region = RegionCarte.Text;
            carte.Pays = PaysCarte.Text;

            
            general.Add("'" + outil.echappement(contenu.Titre)+"'");
            general.Add("'carte'");
            general.Add(  "'" + outil.echappement(contenu.Description)+"'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(carte.Pays) + "'");
            specifique.Add("'" + outil.echappement(carte.Region) + "'");

            connexion.insertContenu("carte", contenu, carte, general, specifique);

            MessageBox.Show("Carte ajoutée");

            AjouterUnMediaValid_Click(sender, e);
        }

        private void BoutonAjouterUnJournalHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Journal journal = new Journal();
            journal.NomJournal = NomJournal.Text;

            
            journal.Date = String.Format("{0:dd/MM/yyyy}", this.DateJournal.Value );

            general.Add("'" + outil.echappement(contenu.Titre) + "'");
            general.Add("'journal'");
            general.Add("'" + outil.echappement(contenu.Description) + "'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(journal.NomJournal) + "'");
            specifique.Add("'" + outil.echappement(journal.Date) + "'");

            connexion.insertContenu("journal", contenu, journal, general, specifique);

            MessageBox.Show("Journal ajouté");

            AjouterUnMediaValid_Click(sender, e);
        }

        private void BoutonAjouterUnLivreHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Livre livre = new Livre();
            livre.Auteur = AuteurLivre.Text;
            livre.Editeur = EditeurLivre.Text;

            general.Add("'" + outil.echappement(contenu.Titre) + "'");
            general.Add("'livre'");
            general.Add("'" + outil.echappement(contenu.Description) + "'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(livre.Auteur) + "'");
            specifique.Add("'" + outil.echappement(livre.Editeur) + "'");

            connexion.insertContenu("livre", contenu, livre, general, specifique);
            MessageBox.Show("Livre ajouté");

            AjouterUnMediaValid_Click(sender, e);
        }

        private void BoutonAjouterUneMusiqueHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Musique musique = new Musique();
            musique.Genre = GenreMusique.Text;
            musique.Compositeur = CompositeurMusique.Text;

            general.Add("'" + outil.echappement(contenu.Titre) + "'");
            general.Add("'musique'");
            general.Add("'" + outil.echappement(contenu.Description) + "'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(musique.Genre) + "'");
            specifique.Add("'" + outil.echappement(musique.Compositeur) + "'");

            connexion.insertContenu("musique", contenu, musique, general, specifique);
            MessageBox.Show("Musique ajoutée");

            AjouterUnMediaValid_Click(sender, e);
        }

        private void BoutonAjouterUnePartitionHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Partition partition = new Partition();
            partition.Genre = GenrePartition.Text;
           

            general.Add("'" + outil.echappement(contenu.Titre) + "'");
            general.Add("'partition'");
            general.Add("'" + outil.echappement(contenu.Description) + "'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(partition.Genre) + "'");


            connexion.insertContenu("partition", contenu, partition, general, specifique);
            MessageBox.Show("Partition ajoutée");

            AjouterUnMediaValid_Click(sender, e);
        }

        private void BoutonAjouterUneVideoHover_Click(object sender, EventArgs e)
        {
            List<string> general = new List<string>();
            List<string> specifique = new List<string>();

            Contenu contenu = new Contenu();
            contenu.Titre = TitreMedia.Text;
            contenu.Description = DescriptionMedia.Text;

            Video video = new Video();
            video.Realisateur = RealisateurVideo.Text;
            video.Producteur = ProducteurVideo.Text;

            general.Add("'" + outil.echappement(contenu.Titre) + "'");
            general.Add("'video'");
            general.Add("'" + outil.echappement(contenu.Description) + "'");
            specifique.Add("10");
            specifique.Add("'" + outil.echappement(video.Realisateur) + "'");
            specifique.Add("'" + outil.echappement(video.Producteur) + "'");

            connexion.insertContenu("video", contenu, video, general, specifique);
            MessageBox.Show("Video ajoutée");

            AjouterUnMediaValid_Click(sender, e);
        }
        private void PictureClean()
        {
            this.RealisateurVideo.Visible = false;
            this.RealisateurVideoMedia.Visible = false;
            this.ProducteurVideo.Visible = false;
            this.ProducteurVideoMedia.Visible = false;
            this.BoutonAjouterUneVideo.Visible = false;
            this.BoutonCarte.Visible = false;
            this.BoutonJournal.Visible = false;
            this.BoutonLivre.Visible = false;
            this.BoutonMusique.Visible = false;
            this.BoutonPartition.Visible = false;
            this.BoutonVideo.Visible = false;
            this.PaysCarte.Visible = false;
            this.PaysCarteMedia.Visible = false;
            this.RegionCarte.Visible = false;
            this.RegionCarteMedia.Visible = false;
            this.BoutonAjouterUneCarte.Visible = false;
            this.DateJournalMedia.Visible = false;
            this.DateJournal.Visible = false;
            this.NomJournalMedia.Visible = false;
            this.NomJournal.Visible = false;
            this.BoutonAjouterUnJournal.Visible = false;
            this.AuteurLivre.Visible = false;
            this.AuteurLivreMedia.Visible = false;
            this.EditeurLivre.Visible = false;
            this.EditeurLivreMedia.Visible = false;
            this.BoutonAjouterUnLivre.Visible = false;
            this.GenreMusique.Visible = false;
            this.GenreMusiqueMedia.Visible = false;
            this.CompositeurMusique.Visible = false;
            this.CompositeurMusiqueMedia.Visible = false;
            this.BoutonAjouterUneMusique.Visible = false;
            this.GenrePartition.Visible = false;
            this.GenrePartitionMedia.Visible = false;
            this.BoutonAjouterUnePartition.Visible = false;
            this.BoutonValiderMediaModif.Visible = false;
            this.BoutonValiderMediaModifHover.Visible = false;

        }

        private void BoutonSupprimerMedia_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonSupprimerMedia.Visible = false;
            this.BoutonSupprimerMediaHover.Visible = true;
        }

        private void BoutonSupprimerMediaHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonSupprimerMediaHover.Visible = false;
            this.BoutonSupprimerMedia.Visible = true;
        }

        private void CleanSupprimerMedia()
        {
            this.ListeMediaSuppr.Visible = false;
            this.BoutonSupprimerMedia.Visible = false;
            this.TitreMediaSuppr.Visible = false;
            this.MotsClefMediaSuppr.Visible = false;
            this.SupprimerUnMediaInterface.Visible = false;
        }

        private void SupprimerUnMediaValid_Click(object sender, EventArgs e)
        {
            this.ListeMediaSuppr.Visible = true;
            this.BoutonSupprimerMedia.Visible = true;
            this.TitreMediaSuppr.Visible = true;
            this.TitreMediaSuppr.Text = "";
            this.MotsClefMediaSuppr.Visible = true;
            this.MotsClefMediaSuppr.Text = "";
            this.SupprimerUnMediaInterface.Visible = true;
            RechercheMediaSuppr();
            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanModifierAdherent(); 
            this.BoutonModifierMedia.Visible = false;
            CleanSupprmierAdherent();
           
            PictureClean();
            
        }

        private void RechercheMediaSuppr()
        {
            this.ListeMediaSuppr.BringToFront();
            this.ListeMediaSuppr.Visible = true;
           
            this.ListeMediaSuppr.AutoGenerateColumns=false;
            // Set the column header names.
            this.ListeMediaSuppr.Rows.Clear();
            this.ListeMediaSuppr.Columns.Clear();
            this.ListeMediaSuppr.ColumnCount = 5;
            this.ListeMediaSuppr.ColumnHeadersVisible = true;

            DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
            checkboxColumn.Width = 30;
            checkboxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
          


            this.ListeMediaSuppr.Columns[0].Name = "Réf";
            this.ListeMediaSuppr.Columns[1].Name = "Titre";
            this.ListeMediaSuppr.Columns[2].Name = "Type";
            this.ListeMediaSuppr.Columns[3].Name = "Description";
            this.ListeMediaSuppr.Columns[0].Width = 30;
            this.ListeMediaSuppr.Columns[2].Width = 60;
            this.ListeMediaSuppr.Columns[3].Width = 1000;

            this.ListeMediaSuppr.DefaultCellStyle.ForeColor = Color.White;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
            dataGridViewCellStyle2.BackColor = System.Drawing.Color.LightSlateGray;

            this.ListeMediaSuppr.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
            this.ListeMediaSuppr.EnableHeadersVisualStyles = false;
            this.ListeMediaSuppr.RowsDefaultCellStyle.BackColor = Color.CornflowerBlue;
            this.ListeMediaSuppr.AlternatingRowsDefaultCellStyle.BackColor = Color.SteelBlue;

   
            ListeMediaSuppr.Rows.Clear();
            List<string> values = new List<string>();
            List<string> champs = new List<string>();
            string tri = "titre";

            if (this.TitreMediaSuppr.Text != "")
            {
                values.Add(TitreMediaSuppr.Text);
                champs.Add("titre");

            }
            else tri = "description";

            if (this.MotsClefMediaSuppr.Text != "")
            {
                values.Add(MotsClefMediaSuppr.Text);
                champs.Add("description");
               
            }

            List<string[]> tmp_list = connexion.rechercheGlobaleGrid("contenu", champs, values, tri, 0, 4);
           
            foreach (string[] tmp in tmp_list)
            {
                
                
                this.ListeMediaSuppr.Rows.Add(tmp);
            }
            checkboxColumn.ThreeState = false;
            checkboxColumn.CellTemplate = new DataGridViewCheckBoxCell();
            ListeMediaSuppr.Columns.Insert(0, checkboxColumn);

         
            
            
          
        }

        private void TitreMediaSuppr_KeyUp(object sender, KeyEventArgs e)
        {
            RechercheMediaSuppr();
        }

        private void MotsClefMediaSuppr_KeyUp(object sender, KeyEventArgs e)
        {
            RechercheMediaSuppr();
        }

        private void BoutonSupprimerMediaHover_Click(object sender, EventArgs e)
        {
            if (this.TitreMediaSuppr.Text == "" && this.MotsClefMediaSuppr.Text == "")
                MessageBox.Show("Veuillez remplir les champs");
            else
            {
                for (int i = 0; i < ListeMediaSuppr.Rows.Count; i++)
                {

                    if (Convert.ToBoolean(ListeMediaSuppr.Rows[i].Cells[0].Value).Equals(true))
                    {
                        connexion.DeleteByID("contenu", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value.ToString());
                    }
                }
                MessageBox.Show("Media supprimé");
                RechercheMediaSuppr();
            }
        }

        

        private void ListeMediaSuppr_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            if (e.ColumnIndex == 0)
            {
                if (ListeMediaSuppr.Rows[e.RowIndex].Cells[0].Value == null)
                {
                    ListeMediaSuppr.Rows[e.RowIndex].Cells[0].Value = true;
                }
                else
                {
                    bool bChecked = (bool)ListeMediaSuppr.Rows[e.RowIndex].Cells[0].Value;
                    ListeMediaSuppr.Rows[e.RowIndex].Cells[0].Value = !bChecked;
                }
            }
        }

        private void CleanModifierMedia()
        {
            this.ListeMediaSuppr.Visible = false;
            this.BoutonModifierMedia.Visible = false;
            this.TitreMediaSuppr.Visible = false;
            this.MotsClefMediaSuppr.Visible = false;
            this.SupprimerUnMediaInterface.Visible = false;
        }

        private void ModifierUnMediaValid_Click(object sender, EventArgs e)
        {
            this.BoutonModifierMedia.BringToFront();
            this.BoutonModifierMediaHover.BringToFront();
            this.ListeMediaSuppr.Visible = true;
            this.BoutonModifierMedia.Visible = true;
            this.TitreMediaSuppr.Visible = true;
            this.MotsClefMediaSuppr.Visible = true;
            this.SupprimerUnMediaInterface.Visible = true;
            this.TitreMediaSuppr.Text = "";
            this.MotsClefMediaSuppr.Text = "";
            RechercheMediaSuppr();
            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            CleanListMedia();
            CleanListAdherent();
            CleanListEmprunt();
            CleanModifierAdherent();
            this.BoutonSupprimerMedia.Visible = false;
            CleanSupprmierAdherent();
            PictureClean();
            
        }

        private void BoutonModifierMedia_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonModifierMedia.Visible = false;
            this.BoutonModifierMediaHover.Visible = true;
        }

        private void BoutonModifierMediaHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonModifierMediaHover.Visible = false;
            this.BoutonModifierMedia.Visible = true;
        }

        private void BoutonAjouterMediaDisabled()
        {
            this.BoutonCarte.Enabled = false;
            this.BoutonJournal.Enabled = false;
            this.BoutonLivre.Enabled = false;
            this.BoutonMusique.Enabled = false;
            this.BoutonPartition.Enabled = false;
            this.BoutonVideo.Enabled = false;
            
        }
        private void BoutonAjouterMediaEnable()
        {
            this.BoutonCarte.Enabled = true;
            this.BoutonJournal.Enabled = true;
            this.BoutonLivre.Enabled = true;
            this.BoutonMusique.Enabled = true;
            this.BoutonPartition.Enabled = true;
            this.BoutonVideo.Enabled = true;

        }

        private void BoutonModifierMediaHover_Click(object sender, EventArgs e)
        {
            if (this.TitreMediaSuppr.Text == "" && this.MotsClefMediaSuppr.Text == "")
                MessageBox.Show("Veuillez remplis les champs");
            else
            {

                this.BoutonValiderMediaModif.Visible = true;
                this.BoutonValiderMediaModif.BringToFront();
                this.BoutonModifierMedia.SendToBack();
                this.BoutonModifierMediaHover.SendToBack();
                this.BoutonModifierMedia.Visible = false;
                this.BoutonModifierMediaHover.Visible = false;
                this.ListeMediaSuppr.Visible = false;
                this.BoutonModifierMedia.Visible = false;
                this.TitreMediaSuppr.Visible = false;
                this.MotsClefMediaSuppr.Visible = false;
                this.SupprimerUnMediaInterface.Visible = false;

                bool flag = false;

                for (int i = 0; i < ListeMediaSuppr.Rows.Count; i++)
                {

                    if (Convert.ToBoolean(ListeMediaSuppr.Rows[i].Cells[0].Value).Equals(true))
                    {
                        flag = true;
                        reference = ListeMediaSuppr.Rows[i].Cells[1].Value + "";
                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "carte")
                        {

                            BoutonAjouterMediaDisabled();

                            this.PaysCarte.Visible = true;
                            this.PaysCarte.Text = connexion.SearchByIdBis("carte", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.PaysCarteMedia.Visible = true;
                            this.RegionCarte.Visible = true;
                            this.RegionCarte.Text = connexion.SearchByIdBis("carte", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 3, 4);
                            this.RegionCarteMedia.Visible = true;

                            this.BoutonCarte.Visible = false;
                            this.BoutonJournal.Visible = true;
                            this.BoutonLivre.Visible = true;
                            this.BoutonMusique.Visible = true;
                            this.BoutonPartition.Visible = true;
                            this.BoutonVideo.Visible = true;
                            this.AjouterUnMediaInterface.Visible = true;



                        }

                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "livre")
                        {
                            BoutonAjouterMediaDisabled();
                            this.AuteurLivre.Visible = true;
                            this.AuteurLivre.Text = connexion.SearchByIdBis("livre", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.AuteurLivreMedia.Visible = true;
                            this.EditeurLivre.Visible = true;
                            this.EditeurLivre.Text = connexion.SearchByIdBis("livre", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 3, 4);
                            this.EditeurLivreMedia.Visible = true;

                            this.BoutonCarte.Visible = true;
                            this.BoutonJournal.Visible = true;
                            this.BoutonLivre.Visible = false;
                            this.BoutonMusique.Visible = true;
                            this.BoutonPartition.Visible = true;
                            this.BoutonVideo.Visible = true;

                            this.AjouterUnMediaInterface.Visible = true;
                        }

                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "journal")
                        {
                            BoutonAjouterMediaDisabled();
                            this.NomJournal.Visible = true;
                            this.NomJournal.Text = connexion.SearchByIdBis("journal", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.NomJournalMedia.Visible = true;
                            this.DateJournal.Visible = true;
                            this.DateJournalMedia.Visible = true;



                            this.BoutonCarte.Visible = true;
                            this.BoutonJournal.Visible = false;
                            this.BoutonLivre.Visible = true;
                            this.BoutonMusique.Visible = true;
                            this.BoutonPartition.Visible = true;
                            this.BoutonVideo.Visible = true;

                            this.AjouterUnMediaInterface.Visible = true;
                        }

                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "partition")
                        {
                            BoutonAjouterMediaDisabled();
                            this.GenrePartition.Visible = true;
                            this.GenrePartition.Text = connexion.SearchByIdBis("partition", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.GenrePartitionMedia.Visible = true;

                            this.BoutonCarte.Visible = true;
                            this.BoutonJournal.Visible = true;
                            this.BoutonLivre.Visible = true;
                            this.BoutonMusique.Visible = true;
                            this.BoutonPartition.Visible = false;
                            this.BoutonVideo.Visible = true;

                            this.AjouterUnMediaInterface.Visible = true;
                        }

                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "musique")
                        {
                            BoutonAjouterMediaDisabled();
                            this.GenreMusique.Visible = true;
                            this.GenreMusique.Text = connexion.SearchByIdBis("musique", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.GenreMusiqueMedia.Visible = true;
                            this.CompositeurMusique.Visible = true;
                            this.CompositeurMusique.Text = connexion.SearchByIdBis("musique", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 3, 4);
                            this.CompositeurMusiqueMedia.Visible = true;

                            this.BoutonCarte.Visible = true;
                            this.BoutonJournal.Visible = true;
                            this.BoutonLivre.Visible = true;
                            this.BoutonMusique.Visible = false;
                            this.BoutonPartition.Visible = true;
                            this.BoutonVideo.Visible = true;

                            this.AjouterUnMediaInterface.Visible = true;
                        }

                        if (ListeMediaSuppr.Rows[i].Cells[3].Value + "" == "video")
                        {
                            BoutonAjouterMediaDisabled();
                            this.RealisateurVideo.Visible = true;
                            this.RealisateurVideo.Text = connexion.SearchByIdBis("video", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 2, 3);
                            this.RealisateurVideoMedia.Visible = true;
                            this.ProducteurVideo.Visible = true;
                            this.ProducteurVideo.Text = connexion.SearchByIdBis("video", "reference", ListeMediaSuppr.Rows[i].Cells[1].Value + "", 3, 4);
                            this.ProducteurVideoMedia.Visible = true;

                            this.BoutonCarte.Visible = true;
                            this.BoutonJournal.Visible = true;
                            this.BoutonLivre.Visible = true;
                            this.BoutonMusique.Visible = true;
                            this.BoutonPartition.Visible = true;
                            this.BoutonVideo.Visible = false;

                            this.AjouterUnMediaInterface.Visible = true;
                        }
                        this.TitreMedia.Visible = true;
                        this.TitreMedia.Text = ListeMediaSuppr.Rows[i].Cells[2].Value + "";
                        this.DescriptionMedia.Visible = true;
                        this.DescriptionMedia.Text = ListeMediaSuppr.Rows[i].Cells[4].Value + "";

                    }

                    if (flag)
                        break;

                }
            }
            
             

           
           

        }

        private void BoutonValiderMediaModif_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonValiderMediaModif.Visible = false;
            this.BoutonValiderMediaModifHover.Visible = true;
        }

        private void BoutonValiderMediaModifHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonValiderMediaModifHover.Visible = false;
            this.BoutonValiderMediaModif.Visible = true;
        }

        private void BoutonValiderMediaModifHover_Click(object sender, EventArgs e)
        {
            
            if (this.BoutonCarte.Visible == false)
            {
                connexion.Update("carte", "pays", this.PaysCarte.Text, "reference = " + reference);
                connexion.Update("carte", "region", this.RegionCarte.Text, "reference = " + reference);
            }
            else if (this.BoutonMusique.Visible == false)
            {
                connexion.Update("musique", "genre", this.GenreMusique.Text, "reference = " + reference);
                connexion.Update("musique", "compositeur", this.CompositeurMusique.Text, "reference = " + reference);
            }
            else if (this.BoutonPartition.Visible == false)
            {
                connexion.Update("partition", "genre", this.GenrePartition.Text, "reference = " + reference);
            }
            else if (this.BoutonVideo.Visible == false)
            {
                connexion.Update("video", "realisateur", this.RealisateurVideo.Text, "reference = " + reference);
                connexion.Update("video", "producteur", this.ProducteurVideo.Text, "reference = " + reference);
            }
            else if (this.BoutonJournal.Visible == false)
            {
                connexion.Update("journal", "date", String.Format("{0:dd/MM/yyyy}", this.DateJournal.Value), "reference = " + reference);
                connexion.Update("journal", "nom_journal", this.NomJournal.Text, "reference = " + reference);
            }
            else if (this.BoutonLivre.Visible == false)
            {
                connexion.Update("livre", "auteur", this.AuteurLivre.Text, "reference = " + reference);
                connexion.Update("livre", "editeur", this.EditeurLivre.Text, "reference = " + reference);
            }

            connexion.Update("contenu","titre",this.TitreMedia.Text, "reference = " + reference);
            connexion.Update("contenu", "description", this.DescriptionMedia.Text, "reference = " + reference);

            MessageBox.Show("Media validé");
            ModifierUnMediaValid_Click(sender, e);
        }

        private void CleanListEmprunt()
        {
            this.ListeDesEmprunts.Visible = false;
            this.BoutonValiderEmprunt.Visible = false;
            this.ListeDesAdherentsInterface.Visible = false;
        }

        private void ListDesEmpruntsValid_Click(object sender, EventArgs e)
        {
            ListEmprunt();

        }
        private void ListEmprunt()
        {
            this.ListeDesEmprunts.Visible = true;   
            this.BoutonValiderEmprunt.Visible = true;
            this.ListeDesAdherentsInterface.Visible = true;


            CleanAjouterAdherent();
            CleanAjouterMedia();
            CleanEmprunterMedia();
            //CleanListMedia();
            this.ListeDesMedias.Visible = false;
            //CleanListAdherent();
            this.ListedesAdherents.Visible = false;
            //CleanListEmprunt();
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();

            PictureClean();
           

            // Set the column header names.
            this.ListeDesEmprunts.Rows.Clear();
            this.ListeDesEmprunts.Columns.Clear();
            this.ListeDesEmprunts.ColumnCount = 7;
            this.ListeDesEmprunts.ColumnHeadersVisible = true;


            //  this.ListeDesMedias.Columns[0].Name = "Rendu";
            this.ListeDesEmprunts.Columns[0].Name = "Réf";
            this.ListeDesEmprunts.Columns[1].Name = "Titre";
            this.ListeDesEmprunts.Columns[2].Name = "Type";
            this.ListeDesEmprunts.Columns[3].Name = "Prénom";
            this.ListeDesEmprunts.Columns[4].Name = "Nom";
            this.ListeDesEmprunts.Columns[5].Name = "Emprunt";
            this.ListeDesEmprunts.Columns[0].Width = 30;
            this.ListeDesEmprunts.Columns[1].Width = 150;
            this.ListeDesEmprunts.Columns[2].Width = 50;


            this.ListeDesEmprunts.DefaultCellStyle.ForeColor = Color.White;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
            dataGridViewCellStyle2.BackColor = System.Drawing.Color.LightSlateGray;

            this.ListeDesEmprunts.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
            this.ListeDesEmprunts.EnableHeadersVisualStyles = false;
            this.ListeDesEmprunts.RowsDefaultCellStyle.BackColor = Color.CornflowerBlue;
            this.ListeDesEmprunts.AlternatingRowsDefaultCellStyle.BackColor = Color.SteelBlue;

            List<string[]> tmp_list = connexion.rechercheGlobaleList("emprunt", "idemprunt", 3);

            foreach (string[] tmp in tmp_list)
            {

                String[] tab1 = connexion.SearchByIdGrid("contenu", "reference", tmp[1], 0, 3);
                String[] tab2 = connexion.SearchByIdGrid("adherent", "identifiant", tmp[2], 1, 4);
                String[] tab3 = new string[tab1.Length + tab2.Length];
                tab1.CopyTo(tab3, 0);
                tab2.CopyTo(tab3, tab1.Length);
                tab3[tab3.Length-1] = tmp[0];

                this.ListeDesEmprunts.Rows.Add(tab3);
            }



            

            DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
            checkboxColumn.Width = 45;
            checkboxColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            checkboxColumn.ThreeState = false;
            checkboxColumn.CellTemplate = new DataGridViewCheckBoxCell();
            checkboxColumn.Name = "Rendu";
            ListeDesEmprunts.Columns.Insert(0, checkboxColumn);
        }

        private void BoutonValiderEmprunt_MouseEnter(object sender, EventArgs e)
        {
            this.BoutonValiderEmprunt.Visible = false;
            this.BoutonValiderEmpruntHover.Visible = true;
        }

        private void BoutonValiderEmpruntHover_MouseLeave(object sender, EventArgs e)
        {
            this.BoutonValiderEmpruntHover.Visible = false;
            this.BoutonValiderEmprunt.Visible = true;
        }

        private void ListeDesEmprunts_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            if (e.ColumnIndex == 0)
            {
                if (ListeDesEmprunts.Rows[e.RowIndex].Cells[0].Value == null)
                {
                    ListeDesEmprunts.Rows[e.RowIndex].Cells[0].Value = true;
                }
                else
                {
                    bool bChecked = (bool)ListeDesEmprunts.Rows[e.RowIndex].Cells[0].Value;
                    ListeDesEmprunts.Rows[e.RowIndex].Cells[0].Value = !bChecked;
                }
            }
        }

        private void BoutonValiderEmpruntHover_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListeDesEmprunts.Rows.Count; i++)
            {
                if (Convert.ToBoolean(ListeDesEmprunts.Rows[i].Cells[0].Value).Equals(true))
                {
                    connexion.DeleteByID("emprunt", "idemprunt", ListeDesEmprunts.Rows[i].Cells[6].Value.ToString());
                }
            }

            MessageBox.Show("Media rendu");

            ListEmprunt();
        }

        private void ValiderEmprunt_MouseEnter(object sender, EventArgs e)
        {
            this.ValiderEmprunt.Visible = false;
            this.ValiderEmpruntHover.Visible = true;
        }

        private void ValiderEmpruntHover_MouseLeave(object sender, EventArgs e)
        {
            this.ValiderEmpruntHover.Visible = false;
            this.ValiderEmprunt.Visible = true;
        }

        private void CleanEmprunterMedia()
        {
            this.ListEmpruntAdherent.Visible = false;
            this.ListEmpruntContenu.Visible = false;
            this.ValiderEmprunt.Visible = false;
            this.ListeDesAdherentsInterface.Visible = false;
        }

        private void EmprunterUnMediaValid_Click(object sender, EventArgs e)
        {
            this.ListEmpruntAdherent.Visible = true;
            this.ListEmpruntContenu.Visible = true;
            this.ValiderEmprunt.Visible = true;
            this.ListeDesAdherentsInterface.Visible = true;

            List<string> tmp = connexion.SelectionGlobale("adherent", "nom", 0, 3);
            foreach (string t in tmp)
                ListEmpruntAdherent.Items.Add("Rèf. " + t);

            tmp = connexion.SelectionGlobale("contenu", "titre", 0, 2);
            foreach (string t in tmp)
                ListEmpruntContenu.Items.Add("Rèf. " + t);

           

            CleanAjouterAdherent();
            CleanAjouterMedia();
            this.ListeDesMedias.Visible = false;
            this.ListedesAdherents.Visible = false;
            this.ListeDesEmprunts.Visible = false;
            this.BoutonValiderEmprunt.Visible = false;
            CleanModifierAdherent();
            CleanModifierMedia();
            CleanSupprimerMedia();
            CleanSupprmierAdherent();

            PictureClean();
            

        }

        private void ValiderEmpruntHover_Click(object sender, EventArgs e)
        {
            if (ListEmpruntAdherent.CheckedItems.Count == 1)
            {

                for (int i = 0; i < ListEmpruntContenu.CheckedItems.Count; i++)
                {

                    List<string> champs = new List<string>();

                    champs.Add("reference");
                    champs.Add("identifiant");

                    List<string> val = new List<string>();

                    val.Add(outil.mySplit((string)ListEmpruntContenu.CheckedItems[i], ' ')[1]);
                    val.Add(outil.mySplit((string)ListEmpruntAdherent.CheckedItems[0], ' ')[1]);



                    connexion.Insert("emprunt", champs, val, true);

                    
                }
                MessageBox.Show("Vous avez ajouté " + ListEmpruntContenu.CheckedItems.Count + " emprunts");
                ListEmpruntAdherent.Items.Clear();
                ListEmpruntContenu.Items.Clear();
                EmprunterUnMediaValid_Click(sender, e);
            }
            else if (ListEmpruntAdherent.CheckedItems.Count > 1)
                MessageBox.Show("Veuillez selectionner un seul adhérent");
            

        }



    }
}
